
import reqwest from 'reqwest' ;

// import Unsplash from 'unsplash-js';

window.ajax = ( () => {
    let Ajax = new Function() ;
    Ajax.prototype = {
        get: function(options) {
            const url = this._getUrl(options.url) ;
            return (
                reqwest({
                    method:'get',
                    url:url,
                    data:options.data,
                    type: 'jsonp',
                    headers: {
                        'Access-Control-Allow-Origin': '*',
                    },
                    type:'jsonp',
                    crossOrigin:true,
                })
            )
        },
        post: function(options){
            const url = this._getUrl(options.url) ;
            return (
                reqwest({
                    method:'post',
                    url:url,
                    type: 'jsonp',
                    headers: {
                        'Access-Control-Allow-Origin': '*',
                    },
                    data:options.data,
                    crossOrigin:true,
                })
            )
        },
        _getUrl:function(url) {
            return ' https://api.douban.com/' + url ;
        },
    };
    return new Ajax();
})();


// window.fetchData = ( () => {
//     let Fetch = new Function() ;
//     // let unsplash  = new Unsplash({
//     //     applicationId:'855dca5283836fd529deb9fcdb48baf0c8f3569ab56d9d8aaf11f67087afc1a0',
//     //     secret:'047044c426a720713c770bfa9fc6cf70772952d94db8244c4dcab845df98397a',
//     //     callbackUrl:'urn:ietf:wg:oauth:2.0:oob',
//     //     // bearerToken:'952bfc00e787fa603c12630106df3a5595bfc5716f5b677e251befbaaba8ad3f'
//     // })

//     let unsplash  = new Unsplash({
//         applicationId:'9ac6e36790a4dbf5c16640fc970793cee6b111cbc4d9046f8234e0a427254572',
//         secret:'6095c5d0734c009e9f1d7e0d252154c570aca482bc547599b742daae7fe64dec',
//         callbackUrl:'ietf:wg:oauth:2.0:oob',
//         // bearerToken:'952bfc00e787fa603c12630106df3a5595bfc5716f5b677e251befbaaba8ad3f'
//     })
//     Fetch.prototype = {
//         get:function (options = {} ) {
//             let { params , url1 , url } = options;

//             let fn = unsplash[url][url1];

//             let args = Object.values(params).map( value => value );

//             return fn.apply(null,args);
//         }
//     };
//     return new Fetch();
// })();